#include "slider.h"
#include "ui_slider.h"

#include <QShortcut>

Slider::Slider(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Slider)
{
    ui->setupUi(this);
    QRect rect = this->geometry();

    ui->horizontalSlider->setMinimum(10);
    ui->horizontalSlider->setMaximum(1000);
    ui->horizontalSlider->setValue(rect.width());
    ui->horizontalSlider->setSingleStep(50);

    ui->verticalSlider->setMinimum(10);
    ui->verticalSlider->setMaximum(1000);
    ui->verticalSlider->setValue(rect.height());
    ui->verticalSlider->setSingleStep(50);

    QShortcut *shortcut1 = new QShortcut(this);
    shortcut1->setKey(QKeySequence("-"));

    QShortcut *shortcut2 = new QShortcut(this);
    shortcut2->setKey(QKeySequence("+"));

    connect(shortcut1, &QShortcut::activated, this, &Slider::subvalue);
    connect(shortcut2, &QShortcut::activated, this, &Slider::addvalue);
}

Slider::~Slider()
{
    delete ui;
}

void Slider::addvalue()
{
    ui->horizontalSlider->setValue(ui->horizontalSlider->value() + 10);
    ui->verticalSlider->setValue(ui->verticalSlider->value() + 10);
}

void Slider::subvalue()
{
    ui->horizontalSlider->setValue(ui->horizontalSlider->value() - 10);
    ui->verticalSlider->setValue(ui->verticalSlider->value() - 10);
}

void Slider::on_horizontalSlider_valueChanged(int value)
{
    QRect rect = this->geometry();
    this->setGeometry(rect.x(), rect.y(), value, rect.height());
}

void Slider::on_verticalSlider_valueChanged(int value)
{
    QRect rect = this->geometry();
    this->setGeometry(rect.x(), rect.y(), rect.width(), value);
}
